package db

import (
	"database/sql"
	"fmt"
	"time"

	_ "github.com/go-sql-driver/mysql"
)

var Dd *sql.DB

func init() {
	tempdb, err := sql.Open("mysql", "root:root@tcp(127.0.0.1:3306)/myoj")
	if err != nil {
		fmt.Println(err)
	}
	Dd = tempdb
}

func Query() map[string]string {
	rows, err := Dd.Query("SELECT * from problems")
	if err != nil {
		fmt.Println(err)
	}
	var id int
	var title, content, poster, answercode string
	var pushtime time.Time
	problems := make(map[string]string, 50)
	for rows.Next() {
		rows.Scan(&id, &title, &content, &pushtime, &poster, &answercode)
		problems[title] = content
	}
	return problems
}
